package net.kem.android.positioner.responsehandler;

import org.xml.sax.SAXException;

/**
 *
 <message>
	<phoneNumber>0507362270</phoneNumber>    <!-- for debug purposes only -->
	<distance>105300</distance>   //.....in meters
	<interval>20</interval>       //.....in sec
 </message>

 <message>
       <commandType>9</commandType>
       <phoneNumber>0547512235</phoneNumber>
       <idMessage>1234</idMessage>
       <messageType>info</messageType>
       <severity>1</severity>
       <title>text goes here
       </title>
       <body>text goes here
       </body>
</message>

 * @author Zhenya
 *
 */
public class ServerAlertResponseHandler extends ResponseHandler {
	public enum AlertSeverity {LOW, NORMAL, HIGH};
	public enum AlertType {INFO, CONFIRM};
	private int commandType;
	private int idMessage;
	private AlertSeverity severity;
	private AlertType messageType;
	private String title;
	private String body;

	@Override
	public void endElement(String uri, String localName, String qName) throws SAXException {
		if(localName.equals("commandType")) {
			commandType = Integer.parseInt(currentValue);
		} else if(localName.equals("idMessage")) {
			idMessage = Integer.parseInt(currentValue);
		} if(localName.equals("severity")) {
			severity = AlertSeverity.values()[Integer.parseInt(currentValue)];
		} else if(localName.equals("messageType")) {
			messageType = AlertType.values()[Integer.parseInt(currentValue)];
		} if(localName.equals("title")) {
			title = currentValue;
		} else if(localName.equals("body")) {
			body = currentValue;
		}
		super.endElement(uri, localName, qName);
	}

	public int getCommandType() {
		return commandType;
	}

	public int getIdMessage() {
		return idMessage;
	}

	public AlertSeverity getSeverity() {
		return severity;
	}

	public AlertType getMessageType() {
		return messageType;
	}

	public String getTitle() {
		return title;
	}

	public String getBody() {
		return body;
	}

	public String toString() {
		String res = severity + " alert of type " + messageType + ": " + title + " | " + body;
		return res;
	}
}